package piwan.editor;

import piwan.*;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Scanner;

import javax.media.opengl.GL;

public class EditVertex {
	public EditVertex() {}
	public EditVertex( Vector2 ipos ) {
		pos.set(ipos);
	}
	
	public ArrayList<EditPoly> getPolys() { return polys; }
	public Vector2 getPosition() { return pos; }
	public void setPosition( Vector2 newpos ) { pos.set(newpos); }
	
	public void addPoly(EditPoly newPoly) { polys.add(newPoly); }
	public void removePoly(EditPoly poly) { polys.remove(poly); }
	
	public void render( GL gl ) {
		gl.glVertex3d(pos.x, 0.0, pos.y);
	}
	
	public void addToPolys() {
		for(EditPoly p: polys)
			p.addVertex(this);
	}
	
	public void removeFromPolys() {
		for(EditPoly p: polys)
			p.removeVertex(this);
	}
	
	public void writeText(Writer file) throws IOException {
		file.write(pos.x + " " + pos.y + "\n");
	}
	
	public void readText(Scanner scan) {
		
		pos.x = scan.nextDouble();
		pos.y = scan.nextDouble();
	}
	
	private ArrayList<EditPoly> polys = new ArrayList<EditPoly>();
	private Vector2 pos = new Vector2();
	public int saveId;
}
